﻿using KELT.KELTObjects.ViewportObjectModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;

namespace KELT.Animation.Animation2D
{

    public class FlyAppearAnimation : IAnimation
    {
        private DoubleAnimation cardAnimation;
        private double distance = 30;

        private int option = 0;

        public FlyAppearAnimation()
        {
            cardAnimation = new DoubleAnimation();

        }


        public void setOption(int option) 
        { 
            this.option = option; 
        }

        public override void SetAnimation(Storyboard myStoryboard, ViewportObj obj)
        {
            animationName = "날아오기";


            cardAnimation.Duration = new Duration(TimeSpan.FromSeconds(endTime - startTime));
            cardAnimation.BeginTime = TimeSpan.FromSeconds(startTime);

            switch (option)
            {
                case 0:
                    cardAnimation.From = obj.getPosition().X - distance;
                    cardAnimation.To = obj.getPosition().X;
                    Storyboard.SetTargetProperty(cardAnimation, new PropertyPath(TranslateTransform3D.OffsetXProperty));
                    break;
                case 1:
                    cardAnimation.From = obj.getPosition().X + distance;
                    cardAnimation.To = obj.getPosition().X;
                    Storyboard.SetTargetProperty(cardAnimation, new PropertyPath(TranslateTransform3D.OffsetXProperty));
                    break;
                case 2:
                    cardAnimation.From = obj.getPosition().Y - distance;
                    cardAnimation.To = obj.getPosition().Y;
                    Storyboard.SetTargetProperty(cardAnimation, new PropertyPath(TranslateTransform3D.OffsetYProperty));
                    break;
                case 3:
                    cardAnimation.From = obj.getPosition().Y + distance;
                    cardAnimation.To = obj.getPosition().Y;
                    Storyboard.SetTargetProperty(cardAnimation, new PropertyPath(TranslateTransform3D.OffsetYProperty));
                    break;
                case 4:
                    cardAnimation.From = obj.getPosition().Z - distance;
                    cardAnimation.To = obj.getPosition().Z;
                    Storyboard.SetTargetProperty(cardAnimation, new PropertyPath(TranslateTransform3D.OffsetZProperty));
                    break;
                case 5:
                    cardAnimation.From = obj.getPosition().Z + distance;
                    cardAnimation.To = obj.getPosition().Z;
                    Storyboard.SetTargetProperty(cardAnimation, new PropertyPath(TranslateTransform3D.OffsetZProperty));
                    break;

            }

            Storyboard.SetTargetName(cardAnimation, AnimationInfo.ANIMATION_TRANSLATE + obj.getIndexNumber());
            myStoryboard.Children.Add(cardAnimation);

        }

        public override void changeAnimation(Storyboard myStoryboard)
        {
            myStoryboard.Children.Remove(cardAnimation);

            cardAnimation.Duration = TimeSpan.FromSeconds(endTime - startTime);
            cardAnimation.BeginTime = TimeSpan.FromSeconds(startTime);

            myStoryboard.Children.Add(cardAnimation);

        }

        public override void deleteAnimation(Storyboard myStoryboard)
        {
            myStoryboard.Children.Remove(cardAnimation);
        }

    }
}
